<!-- 巡更点弹窗 -->

<template>
  <WebModal path="point" :editTitle="`选择${point_MAP.WORD}`" :onSubmit="toSubmit">
    <WebSearch path="point">
      <ParamInput label="巡更点名称" bind="pointName" />
      <ParamTree :label="`所在${CORE.MAP.REGION}`" bind="areaId" :dict="CORE.REGION.DICT" allName />
    </WebSearch>

    <WebTable path="point" class="marginBottom">
      <RowCheckbox />
      <RowText :label="`${point_MAP.WORD}名称`" bind="patrolName" />
      <RowTree :label="`所在${CORE.MAP.REGION}`" bind="areaId" :dict="CORE.REGION.DICT" allName :minWidth="100" />
      <RowText label="关联巡更设备" bind="deviceName" empty="-" />
      <RowText label="关联摄像头" bind="bindVideoName" empty="-" />
    </WebTable>
  </WebModal>
</template>

<script>
// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'

// ============================== 导出组件 ============================== //

export default {
  /**
   * 名称定义 (实际使用名称)
   */
  name: 'PointModal',

  /**
   * 混入列表 (配置选项合并)
   */
  mixins: [CORE.mixWeb(), CORE.mixWeb('point', 'point_')],

  /**
   * 监听属性 (深度 deep 首次 immediate)
   */
  watch: {
    /**
     * 监听巡更点弹窗可见
     */
    point_visible(visible) {
      visible && this.toReset()
    },
  },

  /**
   * 本地方法 (轻量重要在前)
   */
  methods: {
    /**
     * 提交
     */
    toSubmit() {
      const { content, linkAll } = this.one
      this.one.content = this.point_param.rowList.map((item, i) => {
        const matched = (linkAll ? content[0] : content.find((old) => old.pointId === item.id)) || {}
        return {
          pointId: item.id,
          pointName: item.patrolName,
          sourceId: item.deviceId,
          minutes: matched.minutes,
          intervalTime: matched.intervalTime,
          sort: i + 1,
        }
      })
      this.point_closeModal()
    },

    /**
     * 重置
     */
    toReset() {
      const { content } = this.one
      this.point_param.rowList = content.map((item) => ({
        id: item.pointId,
        patrolName: item.pointName,
        deviceId: item.sourceId,
      }))
      this.point_param.idList = content.map(({ pointId }) => pointId)
      this.point_startList(1)
    },
  },
}
</script>
